package com.jic.market.controller.rest;

import com.jic.common.base.vo.RestResult;
import com.jic.market.common.base.MarketBaseController;
import com.jic.market.request.rest.discount.DiscountCancelRequest;
import com.jic.market.request.rest.discount.DiscountOrderCreateRequest;
import com.jic.market.request.rest.discount.DiscountOrderPayRequest;
import com.jic.market.request.rest.discount.DiscountQueryRequest;
import com.jic.market.response.rest.coupon.QueryCouponPersonResponse;
import com.jic.market.response.rest.discount.DiscountQueryResponse;
import com.jic.market.service.rest.discount.DiscountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yinhaijun
 * @date: 2020/4/3
 */
@Slf4j
@Api(tags = {"优惠金额服务"})
@RequestMapping("/rest/discount")
@RestController
public class DiscountAmountRestController extends MarketBaseController {

    @Autowired
    DiscountService discountService;

    @PostMapping("/query-coupon")
    @ApiOperation(value = "查询优惠-可用优惠券", notes="通用活动")
    public List<QueryCouponPersonResponse> queryCoupon(@RequestBody DiscountQueryRequest request){
        log.info("查询优惠-可用优惠券，入参{}-----",request);
        return discountService.queryCoupon(request);
    }

    @PostMapping("/query-shopping-cart-common")
    @ApiOperation(value = "查询优惠-购物车-通用", notes="通用活动")
    public RestResult<DiscountQueryResponse> queryShoppingCartDiscount(@RequestBody DiscountQueryRequest request){
        return executeService(() -> discountService.queryShoppingCartDiscount(request));
    }

    @PostMapping("/query-settlement-page-common")
    @ApiOperation(value = "查询优惠-结算页-通用", notes="通用活动")
    public RestResult<DiscountQueryResponse> queryDiscountTotalAmount(@RequestBody DiscountQueryRequest request){
        log.info("查询优惠-结算页-通用，入参{}-----",request);
        return executeService(() -> discountService.querySettlement(request));
    }


    @PostMapping("/create-common")
    @ApiOperation(value = "创建优惠-创建订单-通用", notes="通用活动")
    public RestResult<List<DiscountQueryResponse>> createDiscount(@RequestBody DiscountOrderCreateRequest request){
        log.info("创建优惠-创建订单-通用，入参{}-----",request);
        return executeService(() -> discountService.create(request));
    }

    @PostMapping("/pay")
    @ApiOperation(value = "支付优惠-付款完成-所有活动", notes="所有活动")
    public RestResult<Integer> payDiscount(@RequestBody DiscountOrderPayRequest request){
        log.info("支付优惠-付款完成-所有活动，入参{}-----",request);
        return executeService(() -> discountService.pay(request));
    }

    @PostMapping("/cancel")
    @ApiOperation(value = "取消优惠-取消订单或退款-所有活动", notes="所有活动")
    public RestResult<DiscountQueryResponse> refundDiscount(@RequestBody DiscountCancelRequest request){
        log.info("取消优惠-取消订单或退款-所有活动，入参{}-----",request);
        return executeService(() -> discountService.cancel(request));
    }

//    // 拼团专用接口
//    @PostMapping("/query-settlement-page-groupon")
//    @ApiOperation(value = "查询优惠-结算页-拼团", notes="拼团专用")
//    public RestResult<DiscountAmountQueryResponse> queryDiscount(@RequestBody GrouponDiscountAmountQueryRequest request){
//        return executeService(() -> discountAmountService.queryDiscount(request));
//    }
//

}
